package com.wawei.seeds.me;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wawei.seeds.R;
import com.wawei.seeds.utils.ImageLoader;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 *
 * Created by t27891 on 15/6/21.
 */
public class MeMainFragment extends Fragment {
    @InjectView(R.id.walnut_back)View backView;
    @InjectView(R.id.walnut_hero_appointment)View appointmentView;
    @InjectView(R.id.walnut_hero_service)View serviceView;
    @InjectView(R.id.walnut_hero_favorite)View favoriteView;
    @InjectView(R.id.walnut_hero_setting)View settingView;

    @InjectView(R.id.walnut_hero_head)ImageView heroHead;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_walnut_hero_self, container, false);
        ButterKnife.inject(this, view);

        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        backView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MeMainFragment.this.getActivity().onBackPressed();
            }
        });

        appointmentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchFragment(MeMainActivity.APPOINTMENT);
            }
        });

        serviceView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchFragment(MeMainActivity.SERVICE);
            }
        });

        favoriteView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchFragment(MeMainActivity.FAVORITE);
            }
        });

        settingView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchFragment(MeMainActivity.SETTING);
            }
        });

        heroHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchFragment(MeMainActivity.SELF_PORTRAIT);
            }
        });

        ImageLoader imageLoader = new ImageLoader(getActivity(), R.drawable.walnut_logo);
        imageLoader.loadImageByResources(R.drawable.walnut_logo, heroHead, true, false);
    }

    private void switchFragment(int tag){
        ((MeMainActivity)getActivity()).onSelectFragment(tag);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}
